// 可以引入这个插件包内的蓝图节点文件、组件文件
import { MyComponent } from "./components/MyComponent.js";
import { BPNode } from "./blueprints/BPNode.js"

/**
 * 导出类
 */
 class MyBox extends THING.Object3D {
  constructor(param = {}) {
    super(param);
    this.box = new THING.Box(param);
    this.box.addComponent(MyComponent);
  }

  onBeforeDestroy() {
    if (this.destroyed) {
      return false;
    }

    this.box.destroy();
    return super.onBeforeDestroy();
  }
}
/**
 * 插件类，是插件入口
 */
class TestPlugin extends THING.BasePlugin {
  constructor() {
    super();
  }

  /**
   * 初始化
   * @param {Object} options
   * @param {Boolean} options.global 配置全局坐标系显示
   */
  onInstall(options = {}) {
    console.log('plugin install complete')
  }
  // 卸载这个插件包时，调用的方法
  onUninstall() {
    console.log('plugin uninstall complete');
  }

  /**
 * 创建方块阵列
 */
  createBoxes(rows = 1, columns = 1, z = 0) {
    if (rows < 1 || columns < 1) {
      console.log('rows and columns must bigger than 0');
      return;
    }
    let boxex = [];
    let deltaX = 2.0;
    let deltaY = 2.0;
    for (let i = 0; i < rows; i++) {
      for (let j = 0; j < columns; j++) {
          let x = i * deltaX;
          let y = j * deltaY;
          let box = new THING.Box({position: [x,y,z]})
          box.style.image = './assets/images/icon.png';
          boxex.push(box);
      }
    }
    return boxex;
  }

}

export { TestPlugin, MyBox, BPNode }